const _ = require('lodash');

module.exports = async (ctx, next) => {
  const token = ctx.cookies.get('token', {encrypt: true});
  if (_.isEmpty(token))
    return ctx.helper.error('请登录后再操作');
  ctx.user = await ctx.app.model.User.findById(JSON.parse(token).user.id);
  await next();
};